﻿using System;
using System.Collections.Generic;

namespace YArchitech.Plumbing
{
	public class HYGroupPumpData : HYPumpData
	{
		public HYGroupPumpData()
		{
			this.m_GroupCurve_H = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_H, this);
			this.m_GroupCurve_N = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_N, this);
			this.m_GroupCurve_E = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_E, this);
			this.m_GroupCurve_NPSH = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_NPSH, this);
			this.m_bIsParallel = false;
			this.m_strGroupName = "泵组";
		}

		public string GetGroupName()
		{
			return this.m_strGroupName;
		}

		public void SetGroupName(string strName)
		{
			this.m_strGroupName = strName;
		}

		public HYGroupPumpData(bool bIsparallel, List<HYPumpData> pumpdata)
		{
			this.m_bIsParallel = bIsparallel;
			this.m_arrData.AddRange(pumpdata);
		}

		public HYGroupPumpData(HYGroupPumpData gp)
		{
			this.m_bIsParallel = gp.IsParallel();
			this.m_arrData.AddRange(gp.m_arrData);
			this.m_strGroupName = gp.GetGroupName();
			this.m_GroupCurve_H = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_H, this);
			this.m_GroupCurve_N = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_N, this);
			this.m_GroupCurve_E = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_E, this);
			this.m_GroupCurve_NPSH = new HYPumpGroupOperationCurve(EPumpCurveType.ePumpCurve_NPSH, this);
		}

		public override double GetMaxQ()
		{
			return 0.0;
		}

		public override double GetMaxH()
		{
			return 0.0;
		}

		public override double GetHbyQ(double d)
		{
			return 0.0;
		}

		public override double GetNbyQ(double d)
		{
			return 0.0;
		}

		public override double GetEbyQ(double d)
		{
			return 0.0;
		}

		public override double GetVaccumbyQ(double d)
		{
			return 0.0;
		}

		public bool IsParallel()
		{
			return this.m_bIsParallel;
		}

		public void SetParaller(bool bParallel)
		{
			this.m_bIsParallel = bParallel;
		}

		public override bool AnalyseCurve(bool bFitCurve = true)
		{
			for (int i = 0; i < this.m_arrData.Count; i++)
			{
				this.m_arrData[i].AnalyseCurve(bFitCurve);
			}
			return true;
		}

		public bool AnsysGroupCurve()
		{
			this.m_GroupCurve_H.m_PumpOwner = this;
			this.m_GroupCurve_N.m_PumpOwner = this;
			this.m_GroupCurve_E.m_PumpOwner = this;
			this.m_GroupCurve_NPSH.m_PumpOwner = this;
			if (this.m_arrData == null || this.m_arrData.Count < 1)
			{
				return false;
			}
			this.nHCurveIndex = this.m_arrData[0].nHCurveIndex;
			this.nNCurveIndex = this.m_arrData[0].nNCurveIndex;
			this.nECurveIndex = this.m_arrData[0].nECurveIndex;
			this.nNPSHCurveIndex = this.m_arrData[0].nNPSHCurveIndex;
			this.CollectOriginCurves();
			this.m_GroupCurve_H.AnsysGroupHCurve();
			this.m_GroupCurve_N.AnsysGroupNCurve();
			this.m_GroupCurve_E.AnsysGroupECurve();
			this.m_GroupCurve_NPSH.AnsysGroupNPSHCurve();
			return true;
		}

		protected void CollectOriginCurves()
		{
			int num = 0;
			foreach (HYPumpData hypumpData in this.m_arrData)
			{
				string strIdentifier = hypumpData.strIdentifier;
				if (this.m_dicOriginSameCurves.ContainsKey(strIdentifier))
				{
					this.m_dicOriginSameCurves[strIdentifier].m_nCount++;
				}
				else
				{
					HYPumpOperationCurveData curveAbout = hypumpData.GetCurveAbout(EPumpCurveType.ePumpCurve_H);
					if (curveAbout != null && !curveAbout.IsEmpty())
					{
						curveAbout.FitCurveParam();
						hypumpData.GetCurveAbout(EPumpCurveType.ePumpCurve_N).FitCurveParam();
						hypumpData.GetCurveAbout(EPumpCurveType.ePumpCurve_E).FitCurveParam();
						hypumpData.GetCurveAbout(EPumpCurveType.ePumpCurve_NPSH).FitCurveParam();
						this.m_dicOriginSameCurves.Add(strIdentifier, new stuSameCurve(num, 1, curveAbout));
					}
				}
				num++;
			}
		}

		public HYPumpGroupOperationCurve GetGroupCurveAbout(EPumpCurveType curveType)
		{
			HYPumpGroupOperationCurve result = this.m_GroupCurve_H;
			switch (curveType)
			{
			case EPumpCurveType.ePumpCurve_H:
				result = this.m_GroupCurve_H;
				break;
			case EPumpCurveType.ePumpCurve_N:
				result = this.m_GroupCurve_N;
				break;
			case EPumpCurveType.ePumpCurve_E:
				result = this.m_GroupCurve_E;
				break;
			case EPumpCurveType.ePumpCurve_NPSH:
				result = this.m_GroupCurve_NPSH;
				break;
			default:
				result = this.m_GroupCurve_H;
				break;
			}
			return result;
		}

		public bool IsSameTo(HYGroupPumpData otherGroupPump)
		{
			bool result = true;
			if (this.m_bIsParallel != otherGroupPump.IsParallel())
			{
				return false;
			}
			if (this.m_arrData.Count != otherGroupPump.m_arrData.Count)
			{
				return false;
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			List<string> groupPumpSPECs = this.GetGroupPumpSPECs(this.m_arrData);
			List<string> groupPumpSPECs2 = this.GetGroupPumpSPECs(otherGroupPump.m_arrData);
			if (groupPumpSPECs.Count != groupPumpSPECs2.Count)
			{
				return false;
			}
			for (int i = 0; i < groupPumpSPECs.Count; i++)
			{
				int num = 0;
				foreach (HYPumpData hypumpData in this.m_arrData)
				{
					if (groupPumpSPECs[i] == hypumpData.StrSpecification)
					{
						num++;
					}
				}
				dictionary.Add(groupPumpSPECs[i], num);
			}
			foreach (string text in dictionary.Keys)
			{
				int num2 = 0;
				using (List<HYPumpData>.Enumerator enumerator = otherGroupPump.m_arrData.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						if (enumerator.Current.StrSpecification == text)
						{
							num2++;
						}
					}
				}
				if (num2 != dictionary[text])
				{
					return false;
				}
			}
			return result;
		}

		private List<string> GetGroupPumpSPECs(List<HYPumpData> pumps)
		{
			List<string> list = new List<string>();
			foreach (HYPumpData hypumpData in pumps)
			{
				if (!list.Contains(hypumpData.StrSpecification))
				{
					list.Add(hypumpData.StrSpecification);
				}
			}
			return list;
		}

		public bool m_bIsParallel;

		public string m_strGroupName;

		public List<HYPumpData> m_arrData = new List<HYPumpData>();

		public Dictionary<string, stuSameCurve> m_dicOriginSameCurves = new Dictionary<string, stuSameCurve>();

		public HYPumpGroupOperationCurve m_GroupCurve_H;

		public HYPumpGroupOperationCurve m_GroupCurve_N;

		public HYPumpGroupOperationCurve m_GroupCurve_E;

		public HYPumpGroupOperationCurve m_GroupCurve_NPSH;
	}
}
